package com.zm.exercise.day04;

import com.zm.exercise.enitiy.User;

import java.util.Set;
import java.util.TreeMap;

/**
 * @Author:Domen
 * @Date:2024/7/15 11:25
 */

public class ComparableTest {
    public static void main(String[] args) {
        TreeMap<User, String> pdata = new TreeMap<User, String>();
        pdata.put(new User("张三", 30), "zhangsan");
        pdata.put(new User("李四", 20), "lisi");
        pdata.put(new User("王五", 10), "wangwu");
        pdata.put(new User("小红", 5), "xiaohong");
        // 得到key的值的同时得到key所对应的值
        Set<User> keys = pdata.keySet();
        for (User key : keys) {
            System.out.println(key.getAge() + "-" + key.getName());

        }

        TreeMap<Integer,String> mapInt = new TreeMap<>();
        mapInt.put(8, "沉默王二");
        mapInt.put(2, "沉默王二");
        mapInt.put(1, "沉默王二");
        mapInt.put(3, "沉默王二");
        mapInt.put(4, "沉默王二");

        System.out.println(mapInt);
    }

}
